<!-- 项目结算 -->
<template>
	<view>
		<bg-search placeholder="请输入项目名称" @search="searchHandler">
		</bg-search>
		<bg-tab :current="current" :tabs="tabs" @tab-change="tabChange"></bg-tab>
		<view class="p-3">
			<u-list v-if="dataList.length>0" @scrolltolower="scrolltolower" style="height: calc(100vh - 345rpx);">
				<view class="bt-block py24px30 mb-3" v-for="i,idx in dataList" :key="idx">
					<view class="flex justify-between align-center">
						<view class="flex-1">
							<bg-desc label="项目编号" :value="i.projectNo"></bg-desc>
							<bg-desc label="项目名称" :valueStyle="{width:'120rpx'}" :value="i.projectName"></bg-desc>
						</view>
						<view>
							<bg-btn v-if="current==0" @click="gotoDetail(i)" style="height:48rpx;font-size: 24rpx; padding-right: 16rpx;padding-left: 16rpx;">填写结算信息</bg-btn>
							<u--image @click="gotoDetail(i)" v-if="current==1" width="24rpx" height="34rpx" src="/static/images/ui/bg/black-arrow.png"></u--image>
						</view>
					</view>
				</view>
				<!-- <view v-if="current==0">
					
				</view>
				<view v-if="current==1">
					<view class="bt-block py24px30" @tap="gotoDetail(2)">
						<view class="flex justify-between align-center">
							<view class="flex-1">
								<bg-desc label="项目编号" value="44444444"></bg-desc>
								<bg-desc label="项目名称" value="雄安项目组"></bg-desc>
							</view>
							<view>
							</view>
						</view>
						
					</view>
				</view> -->
			</u-list>
			<u-empty v-else></u-empty>
		</view>
	</view>
</template>

<script>
	import { getSettleMentProject } from '../../../api/project'
	export default {
		data() {
			return {
				current:0,
				tabs:['未结算','已结算'],
				params:{
					projectName:"",
					isSettlement:0,
					pageNum:1,
					pageSize:10
				},
				total:0,
				dataList:[]
			}
		},
		mounted() {
			this.getData()
			uni.$on("refresh-settle", ()=>{
				this.dataList = []
				this.params.pageNum = 1
				this.getData()
			})
		},
		methods: {
			searchHandler(e){
				this.params.projectName = e
				this.dataList = []
				this.params.pageNum = 1
				this.getData()
			},
			tabChange(e){
				this.current = e
				this.params.isSettlement = e;
				this.dataList = []
				this.params.pageNum = 1
				this.getData()
			},
			scrolltolower(){
				if(this.dataList.length<this.total){
					this.params.pageNum += 1;
					this.getData()
				}
			},
			getData(){
				getSettleMentProject(this.params).then(res=>{
					this.dataList = [ ...this.dataList, ...res.data];
					this.total = res.data.total
				})
			},
			gotoDetail(p){
				if(this.current==0){
					uni.navigateTo({
						url:"/pages/project/settlement/settlement?pid="+p.id
					})
				} else {
					uni.navigateTo({
						url:"/pages/project/settlement/detail?pid="+p.id
					})
				}
				
			}
		}
	}
</script>

<style>

</style>
